package com.sync.platform.common;

import java.io.Serializable;

/**
 * Common result class for API responses
 */
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * Success flag (true: success, false: failure)
     */
    private boolean success;

    /**
     * Response code
     */
    private Integer code;

    /**
     * Response message
     */
    private String message;

    /**
     * Response data
     */
    private T data;

    private Result() {
    }

    private Result(boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * Success result with default message
     *
     * @param <T> Data type
     * @return Result object
     */
    public static <T> Result<T> success() {
        return new Result<>(true, 200, "操作成功", null);
    }

    /**
     * Success result with data
     *
     * @param data Result data
     * @param <T> Data type
     * @return Result object
     */
    public static <T> Result<T> success(T data) {
        return new Result<>(true, 200, "操作成功", data);
    }

    /**
     * Success result with custom message and data
     *
     * @param message Result message
     * @param data Result data
     * @param <T> Data type
     * @return Result object
     */
    public static <T> Result<T> success(String message, T data) {
        return new Result<>(true, 200, message, data);
    }

    /**
     * Failure result with default message
     *
     * @param <T> Data type
     * @return Result object
     */
    public static <T> Result<T> fail() {
        return new Result<>(false, 500, "操作失败", null);
    }

    /**
     * Failure result with custom message
     *
     * @param message Result message
     * @param <T> Data type
     * @return Result object
     */
    public static <T> Result<T> fail(String message) {
        return new Result<>(false, 500, message, null);
    }

    /**
     * Failure result with custom code and message
     *
     * @param code Result code
     * @param message Result message
     * @param <T> Data type
     * @return Result object
     */
    public static <T> Result<T> fail(Integer code, String message) {
        return new Result<>(false, code, message, null);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
